{% extends "layout.html" %}

{% block title %}{{ stock_name }} ({{ stock }}) - 股票实时AI分析系统{% endblock %}

{% block head %}
<style>
    .analysis-section {
        margin-bottom: 20px;
    }
</style>
{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1>{{ stock_name }} <small class="text-muted">{{ stock }}</small></h1>
    <div>
        <h3 class="mb-0">
            {{ last_price }}
            <small class="{% if change > 0 %}text-success{% elif change < 0 %}text-danger{% endif %}">
                {{ change }}%
            </small>
        </h3>
    </div>
</div>

<div class="row mb-4">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header">价格走势</div>
            <div class="card-body">
                <canvas id="stock-chart" class="chart-container"></canvas>
            </div>
        </div>
    </div>
</div>

<div class="row mb-4">
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">短期策略</div>
            <div class="card-body">
                <h5 class="card-title 
                    {% if short_strategy.action == 'buy' %}text-success
                    {% elif short_strategy.action == 'sell' %}text-danger
                    {% else %}text-secondary{% endif %}">
                    {{ short_strategy.action|capitalize if short_strategy else '无策略' }}
                </h5>
                <p class="card-text">{{ short_strategy.reason if short_strategy else '暂无分析' }}</p>
                <div class="d-flex justify-content-between align-items-center mt-3">
                    <div>
                        <span class="badge 
                            {% if short_strategy.confidence == 'high' %}bg-success
                            {% elif short_strategy.confidence == 'medium' %}bg-warning
                            {% else %}bg-secondary{% endif %}">
                            {{ short_strategy.confidence|capitalize if short_strategy else 'Unknown' }}
                        </span>
                    </div>
                    <button class="btn btn-sm btn-outline-primary btn-analyze" data-stock="{{ stock }}"
                        data-analyzer="hikyuu">
                        重新分析
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card">
            <div class="card-header">中期策略</div>
            <div class="card-body">
                <h5 class="card-title 
                    {% if medium_strategy.action == 'buy' %}text-success
                    {% elif medium_strategy.action == 'sell' %}text-danger
                    {% else %}text-secondary{% endif %}">
                    {{ medium_strategy.action|capitalize if medium_strategy else '无策略' }}
                </h5>
                <p class="card-text">{{ medium_strategy.reason if medium_strategy else '暂无分析' }}</p>
                <div class="d-flex justify-content-between align-items-center mt-3">
                    <div>
                        <span class="badge 
                            {% if medium_strategy.confidence == 'high' %}bg-success
                            {% elif medium_strategy.confidence == 'medium' %}bg-warning
                            {% else %}bg-secondary{% endif %}">
                            {{ medium_strategy.confidence|capitalize if medium_strategy else 'Unknown' }}
                        </span>
                    </div>
                    <button class="btn btn-sm btn-outline-primary btn-analyze" data-stock="{{ stock }}"
                        data-analyzer="hikyuu">
                        重新分析
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card">
            <div class="card-header">长期策略</div>
            <div class="card-body">
                <h5 class="card-title 
                    {% if long_strategy.action == 'buy' %}text-success
                    {% elif long_strategy.action == 'sell' %}text-danger
                    {% else %}text-secondary{% endif %}">
                    {{ long_strategy.action|capitalize if long_strategy else '无策略' }}
                </h5>
                <p class="card-text">{{ long_strategy.reason if long_strategy else '暂无分析' }}</p>
                <div class="d-flex justify-content-between align-items-center mt-3">
                    <div>
                        <span class="badge 
                            {% if long_strategy.confidence == 'high' %}bg-success
                            {% elif long_strategy.confidence == 'medium' %}bg-warning
                            {% else %}bg-secondary{% endif %}">
                            {{ long_strategy.confidence|capitalize if long_strategy else 'Unknown' }}
                        </span>
                    </div>
                    <button class="btn btn-sm btn-outline-primary btn-analyze" data-stock="{{ stock }}"
                        data-analyzer="hikyuu">
                        重新分析
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-header">摘要分析</div>
            <div class="card-body">
                <p class="card-text">{{ summary.summary if summary else '暂无分析' }}</p>
                <small class="text-muted">最后更新: {{ last_updated }}</small>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">技术面分析</div>
            <div class="card-body">
                <div class="analysis-section">
                    <h5>趋势分析</h5>
                    <p>{{ technical.trend_analysis if technical else '暂无分析' }}</p>
                </div>

                <div class="analysis-section">
                    <h5>支撑位/阻力位</h5>
                    <p>{{ technical.support_resistance if technical else '暂无分析' }}</p>
                </div>

                <div class="analysis-section">
                    <h5>技术指标信号</h5>
                    <p>{{ technical.indicator_signals if technical else '暂无分析' }}</p>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">基本面分析</div>
            <div class="card-body">
                <div class="analysis-section">
                    <h5>估值分析</h5>
                    <p>{{ fundamental.valuation if fundamental else '暂无分析' }}</p>
                </div>

                <div class="analysis-section">
                    <h5>盈利能力</h5>
                    <p>{{ fundamental.profitability if fundamental else '暂无分析' }}</p>
                </div>

                <div class="analysis-section">
                    <h5>行业前景</h5>
                    <p>{{ fundamental.industry_outlook if fundamental else '暂无分析' }}</p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    // 提供默认空数据以防图表数据不存在
    window.chartData = {{ chart_data | default ('{"dates":[],"opens":[],"highs":[],"lows":[],"closes":[],"volumes":[]}') | safe }};
</script>
{% endblock %}